package com.zhyl.detectibrary.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.IOException;
import java.io.InputStream;

public class BitmapUtils {

    /**
     * 从assets文件夹中获取图片并转换为Bitmap
     *
     * @param context 上下文对象
     * @param fileName assets文件夹中的图片文件名
     * @return Bitmap对象
     */
    public static Bitmap getBitmapFromAssets(Context context, String fileName) {
        try {
            InputStream inputStream = context.getAssets().open(fileName);
            return BitmapFactory.decodeStream(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
